package cn.edu.nuc.film.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.film.common.PageControl;
import cn.edu.nuc.film.common.Pager;
import cn.edu.nuc.film.common.UnitHelper;
import cn.edu.nuc.film.dao.ReviewMapper;
import cn.edu.nuc.film.entity.Review;
import cn.edu.nuc.film.service.interfaces.ReviewService;

@Service
public class ReviewServiceImpl implements ReviewService {
	
	@Autowired
	private ReviewMapper reviewMapper;
	
	/**
	 * 保存影评信息
	 */
	public int saveReview(Review review) {
		int count = reviewMapper.insertSelective(review);
		return count;
	}
	
	/**
	 * 影片的影评列表(分页)
	 */
	public Pager<Review> list( PageControl pc,int filmId) {
		
		int start = (pc.getCurrentindex() - 1) * pc.getPagesize();
		int offset = pc.getPagesize();
		//获取每页的具体数据
		List<Review> list = reviewMapper.list(start,offset,filmId);
		//设置总记录数
		int rscount = 0;
		rscount = reviewMapper.count();
		Pager<Review> pager = UnitHelper.execlist(rscount, list, pc);
		return pager;
	}
	
	
	/**
	 * 影片的影评列表
	 */
	public List<Review> reviewList(int filmId){
		
		List<Review> list = reviewMapper.reviewList(filmId);
		return list;
		
	}

}
